package com.itheima.reggie.controller;

import com.itheima.reggie.CategoryService;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //查询列表
    @GetMapping("/category/findAll")
    public ResultInfo findAll(){
       List<Category> category= categoryService.findAll();
        return ResultInfo.success(category);
    }

    //新增菜系
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category){
        categoryService.save(category);
        return ResultInfo.success(null);
    }

    //修改菜系
    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category){
        categoryService.update(category);
        return ResultInfo.success(null);
    }

    //删除菜系
    @DeleteMapping("/category")
    public ResultInfo deleteMyId(Long id) {
        categoryService.deleteMyId(id);
        return ResultInfo.success(null);
    }
}
